#!/bin/bash

echo "🔄 迁移到 Expo Go 模式"
echo "======================"

# 检查是否有原生代码文件夹
if [ -d "ios" ] || [ -d "android" ]; then
    echo "⚠️  检测到原生代码文件夹，正在删除..."
    rm -rf ios android
    echo "✅ 已删除原生代码文件夹"
fi

echo "📦 检查并替换不兼容的依赖..."

# 检查是否有不兼容的依赖
if grep -q "react-native-fast-image" package.json; then
    echo "🔄 替换 react-native-fast-image 为 expo-image..."
    yarn remove react-native-fast-image
    yarn add expo-image
fi

if grep -q "react-native-mmkv" package.json; then
    echo "🔄 替换 react-native-mmkv 为 expo-secure-store..."
    yarn remove react-native-mmkv
    yarn add expo-secure-store
fi

# 更新 package.json 中的脚本
echo "📝 更新 package.json 脚本..."
sed -i '' 's/"android": "expo run:android"/"android": "expo start --android"/g' package.json
sed -i '' 's/"ios": "expo run:ios"/"ios": "expo start --ios"/g' package.json

echo "🧹 清理缓存..."
rm -rf .expo/
rm -rf node_modules/.cache/
rm -f *.tsbuildinfo

echo "📦 重新安装依赖..."
yarn install

echo "✅ 迁移完成！"
echo ""
echo "🚀 现在你可以运行以下命令启动项目："
echo "   ./start-expo-go.sh"
echo "   或者"
echo "   npx expo start"
echo ""
echo "📱 确保在手机上安装 Expo Go 应用" 